

//
//  HNGetKnowledgePapers.m
//  XDEducation
//
//  Created by 星道 on 17/5/19.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "HNGetKnowledgePapers.h"
#import "HNGetKnowledgePapersCell.h"
@implementation HNGetKnowledgePapers
{
    NSArray <HNGetKnowledgePapersModel *>* _Arr;
    UITableView *_TableView;
}

- (instancetype)init_TableView:(UITableView *)TableView
{
    self = [super init];
    if (self)
    {
        _TableView = TableView;
        _TableView.delegate = self;
        _TableView.dataSource = self;
        _TableView.tableFooterView = [UIView new];
        _TableView.tableHeaderView = [UIView new];
        [_TableView registerNib:[UINib nibWithNibName:[HNGetKnowledgePapersCell description] bundle:nil] forCellReuseIdentifier:@"Cell"];
    }
    return self;
}

- (void)Arr:(NSArray<HNGetKnowledgePapersModel *> *)Arr
{
    
    _Arr = Arr;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        [_TableView reloadData];
    });
    
}



#pragma mark Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _Arr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    HNGetKnowledgePapersCell *Cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    HNGetKnowledgePapersModel *Model = _Arr[indexPath.row];
    Cell.Model = Model;
    
    __block typeof(HNGetKnowledgePapersModel *)WeakModel = Model;
    Cell.DownloadSuccess = ^()
    {
        NSMutableArray *TempArr = [_Arr mutableCopy];
        [TempArr removeObject:WeakModel];
        _Arr = [TempArr copy];
        dispatch_async(dispatch_get_main_queue(), ^{
            [_TableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:(UITableViewRowAnimationAutomatic)];
        });

    };
    return Cell;
}
@end
